package org.example.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * <p>
 *   RESTful API 返回结果封装类
 * </p>
 * @author jinshihui
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RestResult<T> {
    private String code;
    private String msg;
    private T data;

    public static <T> RestResult<T> success(T data) {
        RestResult<T> result = new RestResult<>();
        result.setCode("000000");
        result.setMsg("调用成功");
        result.setData(data);
        return result;
    }

    public static <T> RestResult<T> fail(String code, String msg) {
        RestResult<T> result = new RestResult<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}